package com.ray.controller;

import com.ray.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
public class StudentController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/set")
    public void set(){
        redisTemplate.opsForValue().set("stu","22" );
    }

    @PostMapping("/setStu")
    public void setStu(@RequestBody Student student){
        redisTemplate.opsForValue().set("stu",student );
    }

    @GetMapping("/get/{key}")
    public Student get(@PathVariable("key") String key){
        return  (Student)redisTemplate.opsForValue().get(key);
    }

    @DeleteMapping("delete/{key}")
    public boolean delete(@PathVariable("key") String key){
         redisTemplate.delete(key);
        return redisTemplate.hasKey(key);
    }





}
